package com.xunyin.enums;

/**
 * @author pzr
 * @Description 支付结果
 */
public enum ResultFlag {

    /***
     * 待支付
     */
    WAIT_PAY(0, "待支付"),

    /***
     * 已支付
     */
    PAID(1, "已支付");

    private final String name;
    private final int value;

    ResultFlag(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static ResultFlag parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (ResultFlag e : ResultFlag.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static ResultFlag throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + ResultFlag.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (ResultFlag e : ResultFlag.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
